package jsyf.oa.web.device;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.device.DeviceBrandFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by jjx on 2018/3/8.
 */
@Api(value = "设备品牌接口", description = "设备品牌接口")
@Controller
@RequestMapping("/deviceBrand")
public class DeviceBrandController {

    @Resource
    private DeviceBrandFacade deviceBrandFacade;

    @ResponseBody
    @RequestMapping(value = "/getBrandList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询设备品牌",
            notes = "查询设备品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "brandName:''", dataType = "String", paramType = "body")
    public void getBrandList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject records = this.deviceBrandFacade.getBrandList(jsonData);
        if (null != records) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/removeById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id物理删除品牌",
            notes = "通过id物理删除品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void removeById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceBrandFacade.removeById(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/delById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "通过id逻辑删除品牌",
            notes = "通过id逻辑删除品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "id:''", dataType = "String", paramType = "body")
    public void delById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceBrandFacade.delById(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/update.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改品牌信息",
            notes = "修改品牌信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "jsonData:''", dataType = "String", paramType = "body")
    public void update(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        Boolean records = this.deviceBrandFacade.update(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("isOk", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/updateList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "修改品牌信息",
            notes = "修改品牌信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "jsonData:''", dataType = "String", paramType = "body")
    public void updateList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String records = this.deviceBrandFacade.updateList(jsonData);
        JSONObject obj = new JSONObject();
        obj.put("records", records);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
    }

    @ResponseBody
    @RequestMapping(value = "/getDeviceTypeList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "查询设备类型",
            notes = "查询设备类型 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void getDeviceTypeList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject JSONObj = this.deviceBrandFacade.getDeviceTypeList(jsonData);
        if (null != JSONObj) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(JSONObj));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/add.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加品牌",
            notes = "添加品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject jsonResult = new JSONObject();
        jsonResult.put("id", this.deviceBrandFacade.add(jsonData));
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonResult));
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandList2.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "根据设备类型查询品牌",
            notes = "根据设备类型查询品牌 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{}", dataType = "String", paramType = "body")
    public void getBrandByTypeId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject JSONObj = this.deviceBrandFacade.getBrandList2();
        if (null != JSONObj) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(JSONObj));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("查找失败"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandPage.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取品牌列表",
            notes = "获取品牌列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'brandName':'竹内','requestPage':'1','pageSize':'30'}", dataType = "String", paramType = "body")
    public void getBrandPage(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.deviceBrandFacade.getBrandPage(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandPage2.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取品牌列表",
            notes = "获取品牌列表 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'brandName':'竹内','requestPage':'1','pageSize':'30'}", dataType = "String", paramType = "body")
    public void getBrandPage2(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.deviceBrandFacade.getBrandPage2(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取品牌详细信息",
            notes = "获取品牌详细信息 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'id':'2017121618004C8DBA351757C0A20989'}", dataType = "String", paramType = "body")
    public void getDeviceById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = deviceBrandFacade.getBrandById(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBrandByCompanyId.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取品牌列表根据公司",
            notes = "获取品牌列表根据公司 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'companyId':'201712161613432EAF27DBCCB7D0E6CA'}", dataType = "String", paramType = "body")
    public void getBrandByCompanyId(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.deviceBrandFacade.getBrandByCompanyId(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBankList.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取收款银行",
            notes = "获取收款银行 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{'companyId':'201712161613432EAF27DBCCB7D0E6CA'}", dataType = "String", paramType = "body")
    public void getBankList(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.deviceBrandFacade.getBankList(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjHourRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/addBrandBank.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "添加银行账户",
            notes = "添加银行账户 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "", dataType = "String", paramType = "body")
    public void addBrandBank(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(this.deviceBrandFacade.addBrandBank(jsonData)));
    }
    @ResponseBody
    @RequestMapping(value = "/getBankAndAccountById.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取银行",
            notes = "获取银行 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{brandId:'',intermediaryBank:''}", dataType = "String", paramType = "body")
    public void getBankAndAccountById(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        JSONObject results = this.deviceBrandFacade.getBankAndAccountById(jsonData);
        JSONObject obj=new JSONObject();
        obj.put("bankAccount","");
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(obj));
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getBankAndAccount.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取银行账户",
            notes = "获取银行账户 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "{brandId:''}", dataType = "String", paramType = "body")
    public void getBankAndAccount(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> results = this.deviceBrandFacade.getBankAndAccount(jsonData);
        if (results != null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(results));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }
}
